<?php

namespace App\Kuafu\Shop\Service;

use App\Kuafu\Base\Service\BaseService;
use App\Kuafu\Config\Model\ConfigModel;
use App\Kuafu\Shop\Model\SearchLogModel;

class SearchService extends BaseService
{

    /**
     * 热门搜索
     * @return array
     */
    public static function hotSearch(): array
    {
        $config = ConfigModel::getConfigByTypeKeyOne('applet', 'searchHotConfig');
        return json_decode($config->value ?? '', true) ?? [];
    }


    /**
     * 添加搜索log
     * @param $customerId
     * @param $shopId
     * @param $content
     * @return array
     */
    public static function addSearch($customerId, $shopId, $content): array
    {
        $search = new SearchLogModel();

        $search->customerId = $customerId;
        $search->shopId     = $shopId;
        $search->source     = SearchLogModel::SOURCE_WX_APPLET;
        $search->content    = $content;
        $search->save();

        return ['id' => $search->id];
    }
}
